﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using Coding4Fun.Cannon.Wcf;

namespace Coding4Fun.Cannon.Web
{
	public class Global : System.Web.HttpApplication
	{
		public static DriveService Drive { get; private set; }
		public static AimService Aim { get; private set; }
		public static ShootService Shoot { get; private set; }
		public static SettingsService Settings { get; private set; }
        public static DateTime PhotoTime { get; set; }

		protected void Application_Start(object sender, EventArgs e)
		{
			Logger.SetPath(Server.MapPath(string.Empty));
			Logger.WriteToLog("**********************");
			Logger.WriteToLog("Application Started up");

			Drive = new DriveService();
			Aim = new AimService();
			Shoot = new ShootService();
			Settings = new SettingsService();
			
			Logger.WriteToLog("Instances of all services started");
		}


		protected void Application_BeginRequest(object sender, EventArgs e) { }

		protected void Application_Error(object sender, EventArgs e)
		{
			Logger.WriteToLog("!!!ERROR!!!", Server.GetLastError().ToString());
			Server.ClearError();
		}
		
		protected void Application_End(object sender, EventArgs e)
		{
			Logger.WriteToLog("Application Ending");
			Logger.WriteToLog("Aim Dispose Starting");
            if (Aim != null)
            {
                Aim.Dispose();
            }
			
			Logger.WriteToLog("Aim Dispose Ended");
			Logger.WriteToLog("Application Ended");
			Logger.WriteToLog("**********************");
		}
	}
}